package com.openlogic.logic.adaptor;

import java.io.IOException;

import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.noear.solon.core.handle.UploadedFile;

import com.openlogic.common.plugins.db.api.dto.BaseDataSourceParamDto;
import com.openlogic.datasource.api.enums.DataCategory;
import com.openlogic.logic.service.datasource.ExcelDataSourceService;

/**
* @ClassName: ExcelDataSourceAdapter
* @Description: Excel数据源适配器
* @author weiyongpeng
* @date 2024年12月16日 上午9:27:52
 */
@Component
public class ExcelDataSourceAdapter implements DataSourceAdapter{
	
	@Inject
	private ExcelDataSourceService excelDataSourceService;

	@Override
	public boolean support(String adapter) {
		return DataCategory.EXCEL.getKey().equals(adapter);
	}

	@Override
	public void createDataSource(BaseDataSourceParamDto dataSourceParam, UploadedFile file) {
		try {
			excelDataSourceService.createDataSource(dataSourceParam.getName(), file);
		} catch (IllegalStateException | IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void updateDataSource(String id, BaseDataSourceParamDto dataSourceParam, UploadedFile file) {
		try {
			excelDataSourceService.updateDataSource(id, dataSourceParam, file);
		} catch (IllegalStateException | IOException e) {
			e.printStackTrace();
		}
	}

}
